﻿using System.Text.RegularExpressions;
using System.Threading.Tasks;
using LayuiBlazor.Enums;
using LayuiBlazor.Extensions;
using LayuiBlazor.Utils;
using Microsoft.AspNetCore.Components;

namespace LayuiBlazor.Components
{
    /// <summary>
    /// Progress 进度条组件
    /// </summary>
    public abstract class ProgressBase : LayuiComponentBase
    {
        protected string? ClassName => CssBuilder.Default("layui-progress")
            .AddClass("layui-progress-big", IsBig)
            .Build();

        protected string? BgColor => CssBuilder.Default("")
            .AddClass($"layui-bg-{Color.ToDescriptionString()}", Color != EnumBgColor.None)
            .Build();

        protected string? Width;

        /// <summary>
        /// 获得/设置 是否显示大号进度条
        /// </summary>
        [Parameter] public bool IsBig { get; set; }

        /// <summary>
        /// 获得/设置 背景颜色
        /// </summary>
        [Parameter] public EnumBgColor Color { get; set; }

        /// <summary>
        /// 获得/设置 进度比文本
        /// </summary>
        [Parameter] public string? LayPercent { get; set; }


        protected override void OnInitialized()
        {
            if (!string.IsNullOrWhiteSpace(LayPercent))
            {
                Width = LayPercent.ConvertToPercentString();
                AdditionalAttributes.Add("lay-showPercent", "true");
            }
        }
    }
}
